import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ljy_flutter/get/controller_example/MyLiftcycleController.dart';

// ignore: must_be_immutable
class Getxcontrollerliftcyclemethodexample extends StatelessWidget {
  Getxcontrollerliftcyclemethodexample({super.key});

  Myliftcyclecontroller myliftcyclecontroller = Get.put(Myliftcyclecontroller());

  @override
  Widget build(BuildContext context) {
    print('build widget');
    return Scaffold(
      appBar: AppBar(
        title: const Text('GetX Controller 生命周期'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            GetBuilder<Myliftcyclecontroller>(
              initState: (data) => myliftcyclecontroller.increment(),
              dispose: (data) => myliftcyclecontroller.cleanTask(),
              builder: (controller) {
              return Text('count: ${controller.count}', style: TextStyle(color: Colors.red, fontSize: 20));
            }),

            SizedBox(height: 20,),

            GetBuilder<Myliftcyclecontroller>(
              id: 'unique_id',
              builder: (controller){
              return Text('taskCount: ${controller.taskCount}', style: TextStyle(color: Colors.red, fontSize: 20),);
            }),
            SizedBox(height: 20,),
            GetBuilder<Myliftcyclecontroller>(
              id: 'unique_id_2',
              builder: (controller){
              return Text('taskCount: ${controller.taskCount}', style: TextStyle(color: Colors.blue, fontSize: 20),);
            }),
            SizedBox(height: 20,),
            ElevatedButton(onPressed: (){
              myliftcyclecontroller.incrementTask();
            }, child: Text('增加任务')),
          ],
        ),
      ),
    );
  }
}

/// 打印结果
/// onInit
/// build widget
/// onReady